home *** CD-ROM | disk | FTP | other *** search
/ boe.pres.k12.wv.us / boe.pres.k12.wv.us.zip / boe.pres.k12.wv.us / Utilities / Xerox Workcentre 5335 / Windows Scan / 64-bit_x64 / Japanese / cpsimage.cab / data / xipProcs / readGS.proc < prev    next >
Text File  |  2009-04-23  |  3KB  |  94 lines

  1. #load "sys/stdlib.elf";
  2.  
  3. /* @readGS
  4.   // DESCRIPTION
  5.   readGS - read GhostScript
  6.  
  7.   This procedure takes in an input filename and uses GhostScript to rip the
  8.   the format type PDF or PS to raster pages in JPEG.  A list of XIPIMAGES of
  9.   each page is returned to the caller.  The pages are left compress to minimize
  10.   the memory footprint.
  11.  
  12.   The default resolution is set at 150spi unless a specified value is
  13.   passed in to override it.  
  14.  
  15.   REQUIREMENTS:
  16.   Requires that the image processing classes from the xeng library have been
  17.   loaded via LoadClasses, i.e.,
  18.         LoadClasses (filename: "xeng");
  19.  
  20.   It also requires that you have ghostscript available on your path.  For
  21.   Windows it expects to find "gsWin32" and for Linux/UNIX it expects to find
  22.   "gs".
  23. */
  24.  
  25. PROCEDURE readGS (STRING filename, INTEGER resolution, STRING device)
  26.   RETURNS (ELFLIST imgs)
  27. {
  28.   STATUS status;
  29.   STRING tempname, app, tail;
  30.  
  31.   // Set processing vars; for Windows platform it will have System_Drive
  32.   if ( !device ) device = "jpeg";
  33.  
  34.   if ( "$SystemDrive" != "" ) {
  35.     tempname = "$TEMP/aaaxips";
  36.     app = "gsWin32c -dNOPAUSE ";
  37.     }
  38.   else {
  39.     tempname = "/tmp/aaaxips";
  40.     app = "yes | gs ";
  41.     tail = " 2>&1 > /dev/null";
  42.     }
  43.  
  44.   // Set default resolution
  45.   if ( !resolution ) resolution = 150;
  46.  
  47.   // Setup command string for ghostscript.  app will change if on Windows
  48.   STRING cmd = app;
  49.   cmd = cmd + " -sOutputFile=" + tempname + "%02d." + device;
  50.   cmd = cmd + " -sDEVICE=" + device + " -dBATCH";
  51.   cmd = cmd + " -q -r" + resolution + " " + filename + tail;
  52.  
  53.   // Execute command line and see if we can do it
  54.   try {
  55.      System (cmd: cmd);
  56.   } catch { // "status" object gets the error message
  57.      print status.message;
  58.      return;
  59.   }
  60.  
  61.   // If we made it, get the list of page(s) generated. We need to get data
  62.   // to memory and remove the file.
  63.   INTEGER i;
  64.   STRING  i_str, fname;
  65.   ELFLIST imgNames;
  66.  
  67.   // Limit it to less than 1000 pages
  68.   cmd = " ";
  69.   for (i=1; i<1000; i++) {
  70.     // Compose the file name
  71.     if (i<10)
  72.        i_str = "0" + i;
  73.     else
  74.        i_str = i;
  75.  
  76.     fname = tempname + i_str + "." + device;
  77.     if ( new (FILE, path: fname).isFile() ) {
  78.        if ( device == "jpeg" )
  79.          imgs.insert (entry: i-1,
  80.             obj: readjpg (filename:fname, compressed:1, rawcolor:1).exec() );
  81.        else 
  82.          imgs.insert (entry: i-1,
  83.                       obj: readimage (filename:fname).exec() );
  84.        cmd = cmd + " " + fname;
  85.        }
  86.     else
  87.        break;
  88.     }
  89.  
  90.   System (cmd: "rm " + cmd);
  91.  
  92.   // A list of images is returned through the "imgs" variable
  93. }
  94.